﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using QiangPiao.Person;
using SQ.Base;

namespace QiangPiao
{
    public partial class FrmPerson : Form
    {
        List<Persons> perList = null;
        public FrmPerson()
        {
            InitializeComponent();
            
        }

        private void btnSave_Click(object sender, EventArgs e)
        {
            if (perList != null)
            {

                foreach (Person.Persons p in perList)
                {
                    if (p.CardId == txtCardID.Text)
                    {
                        MessageBox.Show("不能添加重复人员");
                        return;
                    }
                }
            }
            else
            {
                perList = new List<Person.Persons>();
            }

            Persons per = new Persons();
            per.UserName = txtUser.Text;
            per.LType = cmbCardType.SelectedValue.ToString();
            per.CardId = txtCardID.Text;
            per.Phone = txtPhone.Text;
            //per.SeatType = cmbSeatType.SelectedValue.ToString();
            perList.Add(per);


            try
            {
                Person.ConfigBase.UpdatePerson(perList);
                MessageBox.Show("添加成功");
                BindPerson();
            }
            catch (Exception ex)
            {
                Log.WriteLog4Ex("person btnSave_Click", ex);
            }
        }

        private void FrmPerson_Load(object sender, EventArgs e)
        {
            BindPerson();
        }

        private void BindPerson()
        {
            perList = Person.ConfigBase.GetPerson();
            dataGridView1.DataSource = perList;
        }
    }
}
